<?php
/**
 * Navi build
 *
 * Kontaktformular wird erstellt.
 * Request werden verarbeitet.
 *
 * <code>
 * 
 * // Output of main navi in the layout file
 * <?php echo $this->action('mainnavi', 'navi', 'navi'); ?>
 * 
 * // Output of breadcrumb in the layout file
 * <?php echo $this->action('breadcrumb', 'navi', 'navi'); ?>
 * 
 * </code> 
 * 
 * @author Mario Schillermann <info@rockit-flash.com>
 * @encoding UTF-8 äöüßÖÄÜ
 * @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
 * @package Navi
 * @subpackage Navi_NaviController
 * @link $HeadURL$
 * @version SVN: $Id$
 * @phpVersion >= 5.3
 * @todo
 */

class Navi_NaviController extends Zend_Controller_Action
{
    /**
     * Bild the navi with a Array
     * 
     * @staticvar int          $i
     * @staticvar array        $history
     * @staticvar array        $courseElements
     * 
     * @param     array/string $var
     * 
     * @return    string       $var if $var is not a array type
     */
    protected function _arrayList($var)
    {
        static  $i = 1;
        static  $history = array();
        static  $courseElements = array();
        $course = '';
        $page   = '';

        if(is_array($var)) {
            echo '<ul class="navigationLevel' . $i . '">';
            if($i > 1) {
               $courseElements[] = $history[$i-1];
               $course = implode(".", $courseElements) . '.';
            }
            $i++;
            foreach($var as $key => $value) {

                $label = $this->_arrayList($value);

                $page = $course.$key.'.html';
                if ($this->view->course == $page)
                    $active = 'class="active"';
                else
                    $active = 'class=""';

                if (!is_array($value))
                    echo vsprintf('<li><a href="%s" %s>%s</a></li>', array($page, $active, $label));

                $history[$i-1] = $key;
            }
            echo '</ul>';
            array_pop($courseElements);
            $i--;
        } else {
            return $var;
        }
    }
    /**
     * Main navi Output
     * 
     * @return void
     */
    public function mainnaviAction()
    {
        $this->_helper->viewRenderer->setNoRender(true);
        $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/modules/navi/navigation.xml', 'navi');
        $this->_arrayList($config->toArray());
    }

    /**
     * Breadcrumb navi output
     * 
     * @var $breadcrumb breadcrumb string of the view
     * 
     * @return void
     */
    public function breadcrumbAction()
    {
        $breadcrumb = array();
        $breadcrumb = $this->view->breadcrumb;

        $this->view->label = $breadcrumb['label'];
        $this->view->page  = $breadcrumb['page'];
        $this->view->pagesTotal = count($breadcrumb['page']);
        
        
    }
}